package com.cathaypacific.sample.auth.facebook.widget

import android.content.Context
import android.os.Looper
import android.util.Log
import android.widget.Toast
import com.cathaypacific.facebook.login.utils.MetaUtils


/**
 * Created by roy.. on 4/4/2018.
 */
class CrashHandler public constructor() : Thread.UncaughtExceptionHandler {
    private var mContext: Context? = null

    fun setCustomCrashHanler(context: Context) {
        mContext = context
        Thread.setDefaultUncaughtExceptionHandler(this)
    }

    override fun uncaughtException(thread: Thread, ex: Throwable) {
       Log.e(this.javaClass.simpleName, MetaUtils.getStackTrace(ex))
        System.exit(0);
    }

    private fun showToast(context: Context?, msg: String) {
        Thread(Runnable {
            Looper.prepare()
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show()
            Looper.loop()
        }).start()
    }

    companion object {

        val instance = CrashHandler()
    }
}